﻿using System;
using COM.DTO;
using NHibernate;
using COM.Logging;
using NHibernate.Criterion;

namespace DAL.DAO
{
    class DetailDAO
    {
        public static void Add(Detail detail)
        {
            {
                using (ISession session = NHibernateHelper.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.SaveOrUpdate(detail);
                    transaction.Commit();
                }
            }
        }
        public static void Update(Detail detail)
        {
            {
                using (ISession session = NHibernateHelper.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Update(detail);
                    transaction.Commit();
                }
            }
        }

        public static void Remove(Detail detail)
        {
            {
                using (ISession session = NHibernateHelper.OpenSession())
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Delete(detail);
                    transaction.Commit();
                }
            }
        }

        public static Detail GetUserById(String detailId)
        {
            using (ISession session = NHibernateHelper.OpenSession())
                return session.Get<Detail>(detailId);
        }
        public static Detail GetUserByUsername(string hotelId)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                var detail = session
                    .CreateCriteria(typeof(Detail))
                    .Add(Restrictions.Eq("HotelId", hotelId))
                    .UniqueResult<Detail>();
                return detail;
            }

        }
    }
}
